package com.zdhy.it.redis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * 本类为it智慧运维平台使用，redis缓存数据存储获取工具类
 * Created by 梁浩峰 on 2016/10/26 14:58.
 */
public class RedisUtil {
    public static void main(String[] args) {
        Set<String> sentinels = new HashSet<String>();
        sentinels.add(new HostAndPort("work01", 26379).toString());
        sentinels.add(new HostAndPort("work02", 26379).toString());
        JedisSentinelPool sentinelPool = new JedisSentinelPool("mymaster", sentinels,"loong");
        System.out.println("Current hivemaster: " + sentinelPool.getCurrentHostMaster().toString());

        Jedis master = sentinelPool.getResource();
        master.set("username","jack");
        sentinelPool.returnResource(master);


        Jedis master2 = sentinelPool.getResource();

        String value = master2.get("username");
        System.out.println("username: " + value);

    }
}
